<html>
<head><meta charset="utf-8"><title>field is never written · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html">field is never written</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="229533824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229533824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229533824">(Mar 09 2021 at 19:05)</a>:</h4>
<p>to elaborate my last point, <span class="user-mention" data-user-id="125270">@scottmcm</span> , this <a href="https://play.rust-lang.org/?version=beta&amp;mode=debug&amp;edition=2018&amp;gist=4f4e2c18b1d55c4e8e97881dafa8c333">playground</a> only print the following diagnostic:</p>
<div class="codehilite"><pre><span></span><code>warning: field is never read: `f`
 --&gt; src/lib.rs:4:5
  |
4 |     f: Option&lt;String&gt;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
</code></pre></div>
<p>I can understand the issue author’s concern that this is misinterpreted to mean “you can just remove <code>f</code>"</p>



<a name="229534173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534173">(Mar 09 2021 at 19:07)</a>:</h4>
<p>I cannot tell if the issue author <a href="https://github.com/rust-lang/rust/issues/81658#issuecomment-771666253">would accept</a> prepending underscore as an acceptable way to address the issue (they sounded generally dismissive to such feedback at that point), though it sure sounds right to me (especially if one then adds a comment explaining the field’s purpose)</p>



<a name="229534289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534289">(Mar 09 2021 at 19:08)</a>:</h4>
<p>(though it does seem really unfortunate if we e.g. added a "but if you're passing this field to ffi, then please add an underscore..." - 99% of users are going to be pretty surprised at that. Maybe we can say that only for repr(C) types, though.</p>



<a name="229534382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534382">(Mar 09 2021 at 19:08)</a>:</h4>
<p>I woudn’t mention FFI, myself</p>



<a name="229534502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534502">(Mar 09 2021 at 19:09)</a>:</h4>
<p>how would you explain why you should add an _ though? I guess we don't <em>have to</em></p>



<a name="229534517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534517">(Mar 09 2021 at 19:09)</a>:</h4>
<p>we can just offer the suggestion</p>



<a name="229534521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534521">(Mar 09 2021 at 19:09)</a>:</h4>
<p>I would say, “If this field serves some purpose (e.g. a drop effect or is used in FFI), then you can prepend underscore to its name to signal that the field will not be read explicitly."</p>



<a name="229534570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534570">(Mar 09 2021 at 19:09)</a>:</h4>
<p>“not read” != unused</p>



<a name="229534682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534682">(Mar 09 2021 at 19:10)</a>:</h4>
<p>Hm, yeah, that sounds alright :)</p>



<a name="229534694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534694">(Mar 09 2021 at 19:10)</a>:</h4>
<p>I can write the comment at this point</p>



<a name="229534700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229534700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229534700">(Mar 09 2021 at 19:10)</a>:</h4>
<p>I’ve invested enough time. :)</p>



<a name="229535321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/field%20is%20never%20written/near/229535321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/field.20is.20never.20written.html#229535321">(Mar 09 2021 at 19:14)</a>:</h4>
<p>edited the action item!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>